<?php
if(!defined('OSBB')) {
	die();
}
class db {
	
	var $link;
	
	var $querys;
	
	//Auto Function
	function db($host='',$user='',$pass='',$name='') {
		$this->link = @mysql_connect($host, $user, $pass) or die($this->dberror());
		if(! $this->link) {
			$this->error();
		} else {
			$select = @mysql_select_db($name,$this->link) or ($this->dberror());
			if(! $select) {
				$this->dberror();
			}
		}
	}
	
	//Main Functions
	function query($query='') {
		$this->querys++;
		return mysql_query($query);
	}
	function num_rows($query='') {
		return mysql_num_rows($query);
	}
	function fetch_assoc($query='') {
		return mysql_fetch_assoc($query);
	}
	function count() {
		return $this->querys;
	}
	
	function fetch_object($query)
	{
		return mysql_fetch_object($query);
	}
	/**
	 * Makes sure the given string is safe to save in
	 * the database. All data should be run through this
	 * function before beeing placed in a query
	 *
	 * @param String $s String to parse
	 * @return String The finished string
	 */
	function escape_string($s)
	{
		if(get_magic_quotes_gpc())
		{
				$s = stripslashes($s);
		}
		return @mysql_escape_string($s);
	}

	function close()
	{
		return @mysql_close($this->link);
	}
	//Error Functions
	function error() {
		if($this->link) {
			return mysql_error($this->link);
		} else {
			return mysql_error();
		}
	}
	function errno() {
		if($this->link) {
			return mysql_errno($this->link);
		} else {
			return mysql_errno();
		}
	}
	function dberror() {
		//if($this->errno()) {
		echo '<table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000" style="border-collapse:collapse;">
  <tr>
    <th height=26 align="left" background="tile.png">OpenSourceBB Said:</th>
  </tr>
  <tr>
    <td>'.$this->error().'</td>
  </tr>
</table>';
		//}
		exit();
	}
}
?>